package com.controller;

import com.alibaba.fastjson.JSONObject;
import com.common.ErrorCodeEnum;
import com.common.anntation.Log;
import com.common.anntation.SecurityParameter;
import com.common.anntation.SysLog;
import com.common.emums.BusinessType;
import com.common.exception.BusinessException;
import com.common.utils.*;
import com.model.dto.sys.HelloDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = {"公共"})
@Slf4j
/**
 * 结合@Controller和@ResponseBody两个注解功能
 * @ResponseBody :作用在方法上，使方法返回json格式字符串，否则返回跳转路径
 * */
@RestController
public class HelloController {

    @Log(title = "Hello", businessType = BusinessType.OTHER, isSaveRequestData = true)
    @SysLog()
    @GetMapping(value = "/hello", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "Hello")
    @ApiImplicitParams(@ApiImplicitParam(name = "hello", value = "你好", dataType = "Integer"))
    public JSONObject getHello() throws BusinessException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", Constants.USER);
        jsonObject.put("version", "version");
        jsonObject.put("zh-cn", "中文输出测试");
        jsonObject.put("i18n", MessageUtils.message("hello"));
        //log.debug("hello测试");
        Sha256Util.getSHA256("hello");
        //SysUser sysUser= sysUserService.getById(1L,null);
        //UserVO userVO=  EntityConversionUtil.copy(sysUser, UserVO.class);
        //HelloVO helloVo = new HelloVO();
        //helloVo.setStr("hello");
       ;
        jsonObject.put("cpu", SystemInfoUtils.getCPUInfo());
        return Utils.result(ErrorCodeEnum.SUCCESS,jsonObject);
    }

    @Log(title = "Hello", businessType = BusinessType.SELECT, isSaveRequestData = true)
    @SysLog()
    @PostMapping("/postHello")
    @ApiOperation(value = "Post接口名称")
    @SecurityParameter
    public JSONObject getPostHello(@RequestBody @Valid HelloDTO hello) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", Constants.USER);
        jsonObject.put("version", "version");
        jsonObject.put("zh-cn", "中文输出测试");
        jsonObject.put("hello", hello.getHello());
        jsonObject.put("i18n", MessageUtils.message("hello"));
        log.debug("hello测试");

        return Utils.result(ErrorCodeEnum.SUCCESS, jsonObject);
    }
}
